<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改轮播图信息')"/>
    <th:block th:include="include :: jasny-bootstrap-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-picture-edit" th:object="${picture}">
        <input name="ywlsh" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8 fileinput input-group "
                 th:classappend="${photo} ? 'fileinput-exists' : 'fileinput-new'" data-provides="fileinput"
                 style="text-align: center; margin-bottom: 0;">
                <div class="fileinput-preview thumbnail" data-trigger="fileinput"
                     style="width: 200px; height: 150px; margin-right: 10px;">
                    <img th:if="${photo}" th:src="@{'/sys/common/view/' + ${photo}}">
                </div>
                <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span
                        class="fileinput-exists">更改</span><input name="photo" type="hidden" th:value="${photo}"><input
                        id="williamYe" type="file"></span>
                <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">轮播图名称：</label>
            <div class="col-sm-8">
                <input name="photoName" th:field="*{photoName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">轮播图链接：</label>
            <div class="col-sm-8">
                <input name="photoLink" th:field="*{photoLink}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input name="orderNum" th:field="*{orderNum}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input name="remark" th:field="*{remark}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: jasny-bootstrap-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript">
    var prefix = ctx + "control/picture";

    $("#form-picture-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-picture-edit').serialize());
        }
    }

    $('#williamYe').on('change.bs.fileinput ', function (e) {
        // 处理自己的业务
        if (this.files[0]) {
            const formData = new FormData();
            formData.append('file', this.files[0]);
            $.operate.fileUpload(formData, $('input[name="photo"]'));
        } else {
            $('input[name="photo"]').val("");
        }
    });
</script>
</body>
</html>
